<extend name="Public/base" xmlns="http://www.w3.org/1999/html"/>
<block name="content">
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">发布抽奖活动</strong>  <small></small></div>
            </div>

            <hr/>
            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-8 am-u-md-push-1">
                    <form class="am-form am-form-horizontal" id="formdata" enctype="multipart/form-data">
                        <input type="hidden" value="{$id}">
                        <div class="am-form-group">
                            <label for="lottery_id" class="am-u-sm-3 am-form-label">抽奖期数</label>
                            <div class="am-u-sm-9">
                                <if condition="$id gt 0">
                                    第<input type="text" id="lottery_id" placeholder="" required name="lottery_id" value="{$lottery.lottery_id}" readonly>期
                                    <else />
                                    第<input type="text" id="lottery_id" placeholder="" required name="lottery_id" value="{$lottery_id}" readonly>期
                                </if>

                            </div>
                        </div>
                        <div class="am-form-group">
                            <label for="mark_number" class="am-u-sm-3 am-form-label">满标标数</label>
                            <div class="am-u-sm-9">
                                <input type="text" id="mark_number" placeholder="" required name="mark_number" value="{$lottery.mark_number}">
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label for="least_tou" class="am-u-sm-3 am-form-label">起投</label>
                            <div class="am-u-sm-9">
                                <input type="text" id="least_tou" placeholder="" required name="least_tou" value="{$lottery.least_tou}">USDT
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label for="award" class="am-u-sm-3 am-form-label">奖品</label>
                            <div class="am-u-sm-9">
                                <input type="text" id="award" placeholder="" required name="award" value="{$lottery.award}">
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label for="award_price" class="am-u-sm-3 am-form-label">奖品价值</label>
                            <div class="am-u-sm-9">
                                <input type="text" id="award_price" placeholder="" required name="award_price" value="{$lottery.award_price}">USDT
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label for="logo" class="am-u-sm-3 am-form-label">奖品图片 </label>
                            <div class="am-u-sm-9">
                                <img src="{$lottery.award_img}" alt="">
                                <input type="file" id="logo" placeholder="" required name="logo" value="">
                                <span style="color: red;">（只允许上传JPG,PNG,BMP,JPEG格式的图片）</span>
                                <input type="hidden" id="logoinfo" placeholder="" required name="logoinfo" value="{$lottery.award_img}">
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label for="detail" class="am-u-sm-3 am-form-label">奖品详情</label>
                            <div class="am-u-sm-9">
                                <textarea name="detail" id="detail" cols="30" rows="10">{$lottery.award_detail}</textarea>
                                <!--<input type="file" id="detail" placeholder="" required name="detail" value="">-->
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label for="start_time" class="am-u-sm-3 am-form-label">抽奖开始时间</label>
                            <div class="am-u-sm-9">
                                <input type="date" id="start_time" placeholder="" required name="start_time" value="{$lottery.start_time|date='Y-m-d',###}">
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label for="end_time" class="am-u-sm-3 am-form-label">抽奖结束时间</label>
                            <div class="am-u-sm-9">
                                <input type="date" id="end_time" placeholder="" required name="end_time" value="{$lottery.end_time|date='Y-m-d',###}">
                            </div>
                        </div>
                        <!--<div class="am-form-group">-->
                            <!--<label for="is_add_user" class="am-u-sm-3 am-form-label">是否设置补标账户</label>-->
                            <!--<div class="am-u-sm-9">-->
                                <!--<input type="radio" checked class="is_add_user" placeholder="" required name="is_add_user" value="0">不设置补标账户&nbsp;&nbsp;&nbsp;&nbsp;-->
                                <!--<input type="radio" class="is_add_user" placeholder="" required name="is_add_user" value="1">设置补标账户-->
                            <!--</div>-->
                        </form>
                        <div class="am-form-group">
                            <div class="am-u-sm-9 am-u-sm-push-3">
                                <button type="submit" id="sub" class="am-btn am-btn-primary">保存修改</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <hr/>

        </div>
    </div>
</block>
<block name="js">
    <script src="__COMMON__/js/jquery.min.js"></script>
    <script>
        $(function () {
            $("#logo").change(function () {
                var formData = new FormData();
                formData.append("file", $(this).get(0).files[0]);
                $.ajax({
                    url:"{:U('logo_change')}",
                    dataType:'json',
                    type:'POST',
                    data:formData,
                    cache: false,
                    contentType: false,    //不可缺
                    processData: false,    //不可缺
                    success:function(data){
                        console.log(data.path)
                        if(data.code == 1){
                            // alert(data.path);
                            $("#logoinfo").val(data.path);
                            // $("#pic_up_img").attr("src",data.path);//将php传过来的图片付给图片src显示
                            // $("#idcard_up").val(data.path);//将路径保存到hidden里通过form一起保存
                        }else{
                            alert(data.message);
                        }
                    }
                });
            })
            
            $("#sub").click(function () {
                $.ajax({
                    type:"post",
                    dataType:"json",
                    url:"{:U('new_lottery')}",
                    data:{
                        logo:$('#logoinfo').val(),
                        detail:$("#detail").val(),
                        lottery_id:$("#lottery_id").val(),
                        mark_number:$("#mark_number").val(),
                        award:$("#award").val(),
                        award_price:$("#award_price").val(),
                        start_time:$("#start_time").val(),
                        end_time:$("#end_time").val(),
                        least_tou:$("#least_tou").val(),
                    },
                    success:function (data) {
                        if(data.code>0){
                            alert(data.msg);
                            window.location.href=data.data;
                        }else {
                            alert(data.msg);
                        }
                    }
                })
                
            })
        })
    </script>
</block>